import Config from "./Config";
import {DateUtil} from "../../framework/utils/DateUtil";
import {getConfig} from "./ConfigHelper";

/**
 * 活动数据记录. 主要指分享与视频次数的记录.
 */
export class ActivityConfig extends Config {

    // 存储某功能分享配置.
    private data = {};

    constructor() {
        super("activities")
    }

    public onSynced() {
        if (!DateUtil.isToday(this.ts)) {
            cc.log("新的一天");
            this.data = {};
            this.save();
        }
    }

    // 获取当前活动次数.
    public get(scene: string, type: string) {
        const s = this.data[scene] || {};
        return s[type] || 0;
    }

    public add(scene: string, type: string) {
        const s = this.data[scene] || {};
        let times = s[type] || 0;
        s[type] = times + 1;
        this.data[scene] = s;
        this.save();
    }
}

export const activityConfig: ActivityConfig = getConfig(ActivityConfig);